package okl.lab.namesFilter.view.mediators
{
	import okl.lab.components.interfaces.IFilterAndSortList;
	import okl.lab.namesFilter.controller.events.UsersEvent;
	import okl.lab.namesFilter.view.utils.FormatHelper;
	
	import org.robotlegs.mvcs.Mediator;
	
	/**
	 * 
	 *	@author "oleksandr.kulinchenko@gmail.com"
	 */
	public class FilterAndSortMediator extends Mediator
	{
		[Inject]public var view:IFilterAndSortList;
		public function FilterAndSortMediator()
		{
			super();
		}
		
		override public function onRegister():void{
			super.onRegister();
			
			//view setup
			view.dataFilterField="lastName";
			view.dataSortFields=["lastName", "firstName"];
			view.labelFunction=FormatHelper.formatUserName;
			view.enabled=false;
			
			addContextListener(UsersEvent.UPDATED, onUsersLoaded);
		}
		
		protected function onUsersLoaded(event:UsersEvent):void{
			view.dataProvider = event.users;
			view.enabled=(view.dataProvider !=null);
		}
	}
}